<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------

namespace app\dict\order;

use app\dict\pay\PayDict;

/**
 * 订单相关枚举类
 */
class OrderDict
{
    //订单状态
    // 待查验
    const WAIT_CHECK = 1;

    //待协商
    const WAIT_CONSULT = 2;

    // 待申请寄回
    const WAIT_RETURN = 3;

    // 已寄回
    const RETURNED = 4;

    // 寄回已收货
    const RETURNED_RECEIVED = 5;

    //已完成
    const FINISH = 6;

    //已关闭
    const CLOSE = -1;

    /**
     * 订单状态组合
     */
     // 等待查验
    const WAIT_CHECK_GROUP = [
        self::WAIT_CHECK,
        self::WAIT_CONSULT,
    ];
    // 交易变现
    const FINISH_GROUP = [
        self::FINISH
    ];
    // 售后
    const AFTER_SALE_GROUP = [
        self::WAIT_RETURN,
        self::RETURNED,
        self::RETURNED_RECEIVED,
    ];

    // 后台订单
    const BACKEND_GROUP = [
        self::WAIT_CHECK,
        self::WAIT_CONSULT,
        self::FINISH
    ];




    /**
     * 当前订单支持的支付方式
     */
    const ALLOW_PAY = [
        PayDict::WECHATPAY,
        PayDict::ALIPAY,
        PayDict::OFFLINEPAY,
    ];

    const TYPE = 'shop';
    const NORMAL = 1;
    const REFUNDING = 2;

    // 订单创建
    const ORDER_CREATE_ACTION = 'order_create';

    const ORDER_REFUSE_ACTION = 'order_refuse';//订单拒绝

    const ORDER_FINISH_ACTION = 'order_finish';//订单完成
    const ORDER_RETURN_ACTION = 'order_return';//订单寄回





    /**
     * 订单类型以及名称
     * @return array
     */
    public static function getOrderType()
    {
        return [
            'type' => self::TYPE,
            'name' => get_lang('dict_shop_order.order_type_shop')
        ];
    }//买家主动关闭

    /**
     * 获取订单状态组合
     * @param $status
     * @return array|array[]|string
     */

    public static function getStatusGroup($status = '')
    {
        if ($status == 1) {
            return self::WAIT_CHECK_GROUP;
        } elseif ($status == 2) {
            return self::FINISH_GROUP;
        } elseif ($status == 3) {
            return self::AFTER_SALE_GROUP;
        } else {
            return [];
        }
    }

    public static function getStatus($status = '')
    {
        $data = [
            self::WAIT_CHECK => [
                'name' => get_lang('dict_shop_order.status_wait_check'),//待查验
                'status' => self::WAIT_CHECK,


            ],
            self::WAIT_CONSULT => [
                'name' => get_lang('dict_shop_order.status_wait_consult'),//待协商
                'status' => self::WAIT_CONSULT,


            ],
            self::WAIT_RETURN => [
                'name' => get_lang('dict_shop_order.status_wait_return'),//待申请寄回
                'status' => self::WAIT_RETURN,


            ],
            self::RETURNED => [
                'name' => get_lang('dict_shop_order.status_returned'),//已寄回
                'status' => self::RETURNED,


            ],
            self::RETURNED_RECEIVED => [
                'name' => get_lang('dict_shop_order.status_returned_received'),//已收货
                'status' => self::RETURNED_RECEIVED,


            ],
            self::FINISH => [
                'name' => get_lang('dict_shop_order.status_finish'),//已完成
                'status' => self::FINISH,


            ],
            self::CLOSE => [
                'name' => get_lang('dict_shop_order.status_close'),//已关闭
                'status' => self::CLOSE,


            ]

        ];
        if ($status == '') {
            return $data;
        }
        return $data[$status] ?? '';
    }//自动关闭

    /**
     * 订单操作类型
     * @param string $type
     * @return array|mixed|string
     */
    public static function getActionType(string $type = '')
    {
        $data = [
            self::ORDER_CREATE_ACTION => get_lang('dict_shop_order_action.order_create_action'),
            self::ORDER_PAY_ACTION => get_lang('dict_shop_order_action.order_pay_action'),
            self::ORDER_CLOSE_ACTION => get_lang('dict_shop_order_action.order_close_action'),
            self::ORDER_DELIVERY_PART_ACTION => get_lang('dict_shop_order_action.order_part_delivery'),
            self::ORDER_DELIVERY_ACTION => get_lang('dict_shop_order_action.order_delivery_action'),
            self::ORDER_FINISH_ACTION => get_lang('dict_shop_order_action.order_finish_action'),
            self::ORDER_REMARK_ACTION => get_lang('dict_shop_order_action.order_remark_action'),
            self::ORDER_CLOSE_ALLOW_REFUND_ACTION => get_lang('dict_shop_order_action.order_close_allow_refund'),
        ];
        if (!$type) {
            return $data;
        }
        return $data[$type] ?? '';
    }

    /**
     * 关闭方式
     * @param string $type
     * @return array|mixed|string
     */
    public static function getCloseType(string $type = '')
    {
        $data = [
            self::SHOP_CLOSE => get_lang('dict_shop_order_close_type.shop_close'),
            self::BUYER_CLOSE => get_lang('dict_shop_order_close_type.buyer_close'),
            self::AUTO_CLOSE => get_lang('dict_shop_order_close_type.auto_close'),
            self::REFUND_CLOSE => get_lang('dict_shop_order_close_type.refund_close'),
        ];
        if (!$type) {
            return $data;
        }
        return $data[$type] ?? '';
    }
}
